//页面缓存 cache = new _HahsMap();
(function(){
    var _HashMap = window._HashMap = function(s){
        this.init(s);
    };
    
    _HashMap.prototype = {
        init: function(s){
            this._prefix="prefix_";
            this._length = 0;
            this._hit = {};
            this._entity = {};
            if(s && typeof s == 'number' && s > 0){
                this._maxsize = s;
            }else{
                this._maxsize = 10;  
            }
        },
        
        size: function(){
            return this._length;
        },
        
        freeSize: function(){
            return this._maxsize - this._length;
        },
        
        contains: function(key){
            if(this._entity[this._prefix + key]) return true;
                return false;
            },
            
        get: function(key){
            var _key = this._prefix + key;
            if(this.contains(key)){
                this._hit[_key]++;
            }
            return this._entity[_key]; 
        },
        
        getKeys: function(){
            var keys = [];
            var idx = this._prefix.length;
            for(var p in this._entity){
                if(p.indexOf(this._prefix)==0){
                    keys.push(p.substring(idx));
                }
            }
            return keys;
        },
        
        put: function(key,value){
            var _key = this._prefix + key;
            if(!this.contains(key)){
                if(this._length < this._maxsize){   //容量没达到上限
                    this._length++ ;
                }else{                              //达到上限则删除命中次数低的
                    var hits = -1;     //命中次数
                    var props = null;  //属性名
                    for(var p in this._hit){
                        if(p.indexOf(this._prefix)==0){
                            if(hits == -1){
                                hits  = this._hit[p];
                                props = p;
                            }else{
                                if(this._hit[p]< hits){
                                    hits  = this._hit[p];
                                    props = p;
                                }
                            }
                        }
                    }
                    delete this._entity[props];
                    delete this._hit[props];
                }
            };
            this._entity[_key] = value;  //设置属性
            this._hit[_key] = 0; //设置命中次数
        },
        
        remove: function(key){
            var _key = this._prefix + key;
            if(this.contains(key) && this._length>0){
                delete this._entity[_key];
                this._length--;
                               
                delete this._hit[_key];
                return true;
            }
            return false;
        },
        
        clear: function(){
            this._length = 0;
            this._hit = {};
            this._entity = {};
            return true;
        }
    };
})();

Array.prototype.contains=function(obj){
    var arrayStr = "\x0f" + this.join("\x0f") + "\x0f";
    if(arrayStr.indexOf("\x0f" + obj + "\x0f")>=0) return true;
    return false;
}

String.prototype.trim=function(){
    return this.replace(/(^"s+)|("s+$)/g, "");
}

String.prototype.endWith=function(str){
    if(str==null||str==""||this.length==0||str.length>this.length)
        return false;
    if(this.substring(this.length-str.length)==str)
        return true;
    else
        return false;
    return true;
}

String.prototype.startWith=function(str){
    if(str==null||str==""||this.length==0||str.length>this.length)
        return false;
    if(this.substr(0,str.length)==str)
        return true;
    else
        return false;
    return true;
}

function csspx2number(csspx){
    if(csspx.endWith("px")){
        csspx = csspx.substring(0 ,(csspx.length-2));
    }
    return csspx;
}

function showEditDialog(title,textareaId,data){
    showDialog(title,'','success');
    
    var dialogcontent = $("#dialog-content");
    dialogcontent.setTemplateElement(textareaId);
    dialogcontent.processTemplate(data);
    setDialogPosition();
    submitbind();
}

